﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace Authority
{
    /// <summary>
    /// 功能
    /// </summary>
    [Serializable]
    public class Action
    {
        /// <summary>
        /// 字段信息
        /// </summary>
        private FieldInfo valueField;

        /// <summary>
        /// 功能枚举值
        /// </summary>
        public ActionEnum Value { get; set; }

        /// <summary>
        /// 功能名称
        /// </summary>
        public string Name
        {
            get
            {
                var display = Attribute.GetCustomAttribute(this.valueField, typeof(DisaplyAttribute)) as DisaplyAttribute;
                return display == null ? null : display.Name;
            }
        }

        /// <summary>
        /// 功能是否可用
        /// </summary>
        public bool Enable { get; set; }

        /// <summary>
        /// 功能
        /// </summary>
        /// <param name="value">值</param>
        public Action(ActionEnum value)
        {
            this.Value = value;
            this.valueField = typeof(ActionEnum).GetField(value.ToString());
        }

        /// <summary>
        /// 文字显示
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return string.Format("{0}/{1}", this.Name, this.Enable);
        }
    }

}
